package pw.goyd.game.handler.imp;

import org.jboss.netty.channel.ChannelHandlerContext;
import pw.goyd.game.handler.Handler;
import pw.goyd.game.server.LoginList;
import pw.goyd.subscribe.PlayerCustomer;

public class EXITGAME extends Handler {

    @Override
    public void handle() {
        process(getCtx());
    }

    /**
     * 退出游戏静态共用
     *
     * @param ctx channelhandlercontext
     */
    public static void process(ChannelHandlerContext ctx) {
        long id = ctx.getChannel().getId();
        PlayerCustomer p = LoginList.getPlayer(id);
        if (p == null)
            return;

        if (p.getRoomID() == -1)    //	不在游戏中才能正常退出
            LoginList.removePlayer(id);
        ctx.getChannel().close();
    }

}
